<template>
  <el-dialog
    v-model="dialogVisible"
    title="修改腔型物料"
    width="900px"
    @close="closeDialog"
  >
    <el-form label-width="120px" :model="state.queryForm">
      <el-row :gutter="12">
        <el-col :span="12">
          <el-form-item label="装箱方式">
            <el-input v-model="state.queryForm.pickBoxFlag" placeholder="" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="toSave">保存</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
  import { changeCavityInvApi } from '@/api/equip/mold_api'

  const $baseLoading = inject('$baseLoading')
  const $baseMessage = inject('$baseMessage')

  const dialogVisible = ref(false)
  const state = reactive({
    queryForm: {},
  })

  const openDialog = (value) => {
    console.log(value)
    dialogVisible.value = true
    state.queryForm.pkCavityInv = value
  }

  const toSave = async () => {
    const load = $baseLoading()
    try {
      const { code, msg } = await changeCavityInvApi(state.queryForm)
      if (code === 2000) {
        $baseMessage(msg, 'success')
        dialogVisible.value = false
        _emit('success-callback')
      } else {
        $baseMessage(msg, 'error')
      }
    } finally {
      load.close()
    }
  }

  defineExpose({
    openDialog,
  })
  const _emit = defineEmits(['success-callback'])
</script>
